//常用图片
var picUserHead = "/ApiCloud/assets/img/userHead.jpeg"


//APP部署环境设置
var AppCodeEnv = 1;//0=LOCAL;1=SEVER
var AppDevEvn = 1;//0=Prod;1=DEV

//数据配置
var version = "1.00";
var VI = "714a08411a995a07bc5fa247f5f66bc5";

//网络请求配置
// var pageUrl = "http://192.168.0.5:8081";
// var pageApi = "http://192.168.0.5:8081";
// var baseUrl = "http://192.168.0.5:83";
// var baseApi = "http://192.168.0.5:83";
//
// var loggerUrl = "http://192.168.0.5:4237";


//网络请求配置-郭
var pageUrl = "http://photo.zhencaidiy.com";
var pageApi = "http://photo.zhencaidiy.com";
var baseUrl = "";
var baseApi = "http://photo.zhencaidiy.com";
//
// var loggerUrl = "http://127.0.0.1";
//
//
// var pageUrl = "http://192.168.1.5:8081";
// var pageApi = "http://192.168.1.5:8081";
// var baseUrl = "http://192.168.1.5:83";
// var baseApi = "http://192.168.1.5:83";
// var loggerUrl = "http://192.168.1.5:4237";

// var pageUrl = "http://192.168.43.207:8081";
// var pageApi = "http://192.168.43.207:8081";
// var baseUrl = "http://192.168.43.207:82";
// var baseApi = "http://192.168.43.207:82";



// var baseUrl = "http://photo.sano100.com";
// var baseApi = "http://photo.sano100.com";

//图片上传设置，需要在页面加载相应JS
var toOSS = 1;//0:上传到服务器，1：上传到OSS
var ossUrl = 'http://sano100-tjb.oss-cn-beijing.aliyuncs.com';


//*********基础功能重新封装**************//
function getAssetBaseUrl() {
    if (toOSS == 1) {
        return ossUrl
    }else {
        return baseUrl
    }
}

function picUrl(url) {
    if (url == undefined) {
        return getAssetBaseUrl();
    }else {
        return getAssetBaseUrl() + url;
    }
}


//信息输出
var MyAppLogStatus = 2;

function isFalse(param) {
    if (param == ''){
        return false
    }
    if (param ==[]) {
        return false
    }
    if (param == undefined){
        return false
    }
    if (param == {}){
        return false
    }
    if (param == 0){
        return false
    }
    if (param == "0"){
        return false
    }
    return true
}
function isTrue(param) {
    if (param == ''){
        return false
    }
    if (param ==[]) {
        return false
    }
    if (param == undefined){
        return false
    }
    if (param == {}){
        return false
    }
    if (param == 0){
        return false
    }
    if (param == "0"){
        return false
    }
    return true
}

function logHtml(info) {
    // apiLog(info)
}

var log  = function (info){
    if(MyAppLogStatus == 1){
        console.log(info);
    }
    if(MyAppLogStatus == 2){
        logHtml(
            "==========================================" + "<br>" + "caller:" + log.caller+ "<br>"
            + "--------------------------------------------------------------------------" + "<br>"
            + info + "<br>"
            + "==========================================" + "<br><br><br><br>"
        );
    }
}
function logJson(info){
    if(MyAppLogStatus == 1){
        console.log(JSON.stringify(info));
    }
    if(MyAppLogStatus == 2){
        logHtml(
            "==========================================" + "<br>" + "caller:" + log.caller + "<br>"
            + "------------------------------------------------------------------------" + "<br>"
            + JSON.stringify(info) + "<br>"
            + "==========================================" + "<br><br><br><br>"
        );
    }
}


//URL中的参数转对象
function getDataFromUrl(data){
    var queryArr = data.split("?");
    return queryArr[1];
}
function getDataFromQuery(data){
    var result = {};
    var queryArr = data.split("&");
    queryArr.forEach(function(item){
        var value = item.split("=")[1];
        var key = item.split("=")[0];
        result[key] = value;
    });
    return result;
}

//删除所有本地数据
function delAllLocData(){
    api.clearCache(function() {
        api.toast({
            msg: '清除完成'
        });
    });
}




//******************用户相关功能******************
function getUser(){
    var user = getLocData("user");
    try{
        user = JSON.parse(user);
    }catch(e){
        return "";
    }finally{}
    return user;
}

function getUid(){
    var user = getUser();
    return user.id
}

function chkUser(){
    try{
        var uid = getUid();
    }catch(e){
        goto("userLogin",{});
        return;
    }finally{}
    if(uid == undefined){
        goto("userLogin",{});
        return;
    }
    return uid;
}

//**********************图片展示相关功能*********************

function objDelIndex(obj, index) {
    var tmp = {};
    for (var i in obj) {
        if (i != index) {
            tmp[i] = obj[i]
        }
    }
    return tmp;
}

var inArray = function(needle, array) {
    if (array) {
        if (Array.prototype.indexOf) {
            return Array.prototype.indexOf.call(array, needle);
        }

        for (var i = 0, length = array.length; i < length; i++) {
            if (array[i] === needle) {
                return i;
            }
        }
    }
    return -1;
};
function objDelValue(obj, value) {
    var tmp = {};
    for (var i in obj) {
        if (obj[i] != value) {
            tmp[i] = obj[i]
        }
    }
    return tmp;
}


function arrayDelIndex(array, index) {
    var tmp = [];
    array.map(function (data, i) {
        if (i != index) {
            tmp.push(data)
        }
    })
    return tmp;
}

function arrayDelValue(array, value) {
    var tmp = [];
    array.map(function (data, i) {
        if (data != value) {
            tmp.push(data)
        }
    })
    return tmp;
}
function arrayReplaceValue(array, find,replace) {
    var tmp = [];
    array.map(function (data, i) {
        if (data != find) {
            tmp.push(data)
        }else{
            tmp.push(replace)
        }
    })
    return tmp;
}




//这个是用来创建对象用的，暂时不知道为啥
var Class = { // 全局静态类, 用于声明一个新的类并提供构造函数支持
    create: function() {
        return function() { // 返回一个函数, 代表着这个新声明的类的构造函数
            // 一个命名为initialize的函数将被这个类实现作为类的构造函数
            this.initialize.apply(this, arguments);// initialize函数将在你实例化一个变量的时候被调用执行(即上面7个步骤中的第5步)
        }
    }
}

function createForm(en) {
    var form = {};
    logJson(en)
    for(var i in en){
        form["form[" + i +"]"] = en[i]
    }
    if (en.id !== undefined && isTrue(en.id)) {
        form["id"] = en.id
    }
    return form;
}
function recreateEn(item) {
    var data= {}
    for (var i in item) {
        var keys = i.split("_")
        var str = ""
        keys.map(function (data, index) {
            if (index !== 0){
                str += data
            }
        })
        data[ str ] = item[i]
    }
    return data
}

function clearEn(en) {
    var data= {}
    for (var i in en) {
        data[ i ] = ""
    }
    return data
}

function getDate() {
    return new Date().getFullYear() + "-" + ((new Date().getMonth()+1)<10?"0"+(new Date().getMonth()+1):(new Date().getMonth()+1)) + "-" + new Date().getDate()
}
